package Commands;


import domain.Controller;

import domain.Subject;

import java.io.IOException;

import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class CmdSavePuljer extends Command
{
  protected String nextJspUrl = 
    "userStory4.jsp"; 
  CommandFactory comFac;
  Controller controller;

  public void init(CommandFactory comFac, Controller c)
    throws ServletException 
  {
    this.comFac = comFac;
    this.controller = c;
  }

  public void execute(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException 
  {
    Command command;
    //HttpSession session = req.getSession();
    //session.setAttribute("puljer", controller.getPuljer());
    //List<Pulje> puljer = controller.getPuljer();
    //for (int i = 0; i < puljer.size(); i++)
    {
      //System.out.println("whatever: " + puljer.get(i).getPuljeid() + " " + puljer.get(i).getSubjectid());
    }
    nextJspUrl = req.getParameter("ref") + ".jsp";
    List<Subject> subjects = controller.getPulje1();
    for (int i = 0; i < subjects.size(); i++) 
    {
      System.out.println("Cmd: " + subjects.get(i).getId());
    }
    List<Subject> subjects2 = controller.getPulje2();
    for (int i = 0; i < subjects2.size(); i++) 
    {
      System.out.println("Cmd2: " + subjects2.get(i).getId());
    }
    controller.savePuljer();
  }
  
  public String getNextJspUrl()
  {
    return nextJspUrl;
  }
}

